package com.dubbo.cp.logcenter.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dubbo.cp.logcenter.entity.LogEntity;
import com.dubbo.cp.logcenter.mapper.LogMapper;
import com.dubbo.cp.logcenter.service.LocalLogService;

@Service
public class LogServiceImpl implements LocalLogService {
	@Autowired
	private KafkaTemplate<String, String> template;
	@Autowired
	private LogMapper logMapper;

//	@GlobalTransactional(name="my_test_tx_group")
//	@Transactional
	public void sendDemoLog(String logText) {
		
		LogEntity entity = new LogEntity();
		entity.setUsername("SYSTEM");
		entity.setLogText((String) logText);
		logMapper.addlog(entity.getUsername(),logText);
//		throw new RuntimeException();

	}

	public void sendUserLog(String username, String logText) {
		
//		template.send("dubbo-log", logText);
		LogEntity entity = new LogEntity();
		entity.setUsername("ADMIN");
		entity.setLogText((String) logText);
//		logMapper.insert(entity);
		logMapper.addlog(entity.getUsername(),logText);
	}

}
